<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>代码生成器</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="${ctx}/layui/css/layui.css" media="all"/>
    <link rel="stylesheet" href="${ctx}/systemStatic/style/admin.css">
    <link rel="stylesheet" href="${ctx}/iconfont/iconfont.css"/>
    <link rel="stylesheet" href="${ctx}/css/public.css">
    <script type="text/javascript">
        var __ctx = "${ctx}";
    </script>
</head>
<body>

<title>代码生成器</title>
<!-- 你的HTML代码 -->
<div style="margin: 10px">
    <table id="codeGenTable" lay-filter="codeGenTable"></table>
</div>
<!-- 用户信息列表头部工具栏 -->
<script type="text/html" id="headerToolsBar">
    <div class="ccpui-enterSel">
        <div class="layui-btn-container">
            <a class="layui-btn layui-btn-sm" lay-event="batchGen">
                <i class="layui-icon layui-icon-add-1"></i>
                <span>批量生成代码</span>
            </a>
            <a class="layui-btn layui-btn-sm" lay-event="query">
                <i class="layui-icon layui-icon-search"></i>
                <span>查询</span>
            </a>
            <button class="layui-btn layui-btn-sm " lay-event="reset">
                <i class="layui-icon layui-icon-refresh"></i>
                <span>重置</span>
            </button>
        </div>

        <form class="layui-form" action="" lay-filter="queryForm" style="margin-right: 30px;" onsubmit="return false">
        <div class="layui-row" style="margin-top: 10px;">
            <div class="selch table-top-filter">
                <div class="table-filter-alone">
                    <label class="layui-form-label">表名称</label>
                    <input type="text" name="Q_tableName_SL" class="layui-input tableName filter-value" placeholder="表名称"/>
                </div>
                <div class="table-filter-alone">
                    <label class="layui-form-label">创建时间</label>
                    <input type="text" name="Q_start_time_DL" autocomplete="off" placeholder="开始时间"
                           class="layui-input start_time filter-value">
                    <span style="float:left;margin-left:38px">—</span>
                    <input type="text" name="Q_end_time_DG" autocomplete="off" placeholder="结束时间"
                           class="layui-input end_time filter-value" style="margin-left: 38px;">
                </div>

            </div>
        </div>
    </form>
    </div>
</script>
<!-- 右侧工具栏 -->
<script type="text/html" id="rightToolsBar">
    <a class="layui-btn layui-btn-xs" lay-event="genCode" style="margin-right: 10px;">生成代码</a>
    <a class="layui-btn layui-btn-xs" lay-event="tableInfo" style="margin-right: 10px;">表字段信息</a>
</script>
<script src="${ctx}/public/component.js" type="text/javascript"></script>
<script src="${ctx}/layui/layui.js"></script>
<script>
    //一般直接写在一个js文件中
    layui.config({
        base: serverPath.systemPath + staticPath.systemPath //静态资源所在路径
    }).extend({
        index: 'index' //主入口模块
    }).use(['index','table', 'layer', 'form', 'laydate', 'setter','totalFilter', 'commons','common'], function () {

        var layer = layui.layer;
        var form = layui.form;
        var $ = layui.jquery;
        var table = layui.table;
        var setter = layui.setter;
        var laydate = layui.laydate;
        var nowTime = new Date().valueOf();
        var common = layui.common;
        var max = null;
        var totalFilter = layui.totalFilter;
        var commons = layui.commons;

        var tableH=commons.tabHeight('full-70');

        //第一个实例
        table.render({
            elem: '#codeGenTable'
            , url: '${ctx}/extend/codeGen/list'
            , page: true //开启分页
            ,defaultToolbar: ['filter', 'print']
            , toolbar: '#headerToolsBar'
            , title: '数据库表信息'
            , height: tableH
            , method: 'post'
            , cols: [[ //表头
                {field: 'sn', type: 'numbers', title: '序号', fixed: 'left'}
                , {type: 'checkbox', fixed: 'left'}
                , {field: 'tableName', title: '表名称', sort: true}
                , {field: 'tableComment', title: '表描述'}
                , {
                    field: 'createTime', title: '创建时间'
                    , templet: function (d) {
                        return component.timeData(d.createTime);
                    },
                    sort: true
                }
                , {
                    field: 'updateTime', title: '更新时间'
                    , templet: function (d) {
                        return component.timeData(d.updateTime);
                    },
                    sort: true
                }
                , {
                    fixed: 'right',
                    align: 'center',
                    title: '操作',
                    toolbar: '#rightToolsBar'
                }
            ]],done:function () {
                common.tableSelectCon('.ccpui-enterSel .layui-form input','a[lay-event=query]','.ccpui-enterSel');
            }
        });

        totalFilter.init('codeGenTable');

        //监听用户信息列表头部工具栏事件
        table.on('toolbar(codeGenTable)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            var data = checkStatus.data;
            switch (obj.event) {
                case 'batchGen':
                    //批量生成
                    if (data.length === 0) {
                        layer.msg('请先选择一行数据！');
                    } else {
                        var seletTableNames = [];
                        for (var i = 0; i < data.length; i++) {
                            seletTableNames.push(data[i].tableName);
                        }
                        var tableName = seletTableNames.join(",");
                        layer.confirm('确定批量生成当前选中项吗？', function (index) {
                            layer.open({
                                type: 2,
                                title: "代码生成基本信息",
                                area:  ['565px', '520px'],
                                content:'${ctx}/extend/codeGen/view/add?tableName='+tableName+'&batch=true', //这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
                            });
                            layer.close(index);
                        })
                    }
                    break;
                case 'query':
                    common.tableConditionRender("codeGenTable", "queryForm", {where: {}}, false);
                    reflashDate();
                    break;
                case "reset":
                    common.tableConditionRender("codeGenTable", "queryForm", {where: {}}, true);
                    commons.reflashDate({startName:'.start_time',endName:'.end_time'});
                    break;
            }
            ;
        });

//监听行工具事件
        table.on('tool(codeGenTable)', function (obj) {
            var data = obj.data, //获得当前行数据
                layEvent = obj.event; //获得 lay-event 对应的值

            switch (layEvent){
                case "genCode":
                    var tableName = data.tableName;
                    layer.open({
                        type: 2,
                        title: "代码生成基本信息",
                        area: ['565px', '600px'],
                        content:'${ctx}/extend/codeGen/view/add?batch=false&tableName='+tableName //这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
                    });
                    break;
                case "tableInfo":
                    var tableName=data.tableName;
                    var tableComment=data.tableComment;
                    layer.open({
                        type: 2,
                        title: "表字段信息",
                        area: ['1100px', '600px'],
                        content:'${ctx}/extend/codeGen/view/showinfo?tableName='+tableName, //这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
                    });
                    break;
            }
        });
        reflashDate();

        /*刷新时间控件*/
        function reflashDate() {
            var start = laydate.render({
                elem: '.start_time',
                type: 'date',
                //format: 'yyyy-MM-dd',
                max: nowTime,
                done: function (value, date, endDate) {
                    endMax = end.config.max;
                    end.config.min = date; //最大时间为结束时间的开始值  
                    end.config.min.month = date.month - 1;
                    $("input[name='start_time']").val(value);
                }
            });
            var end = laydate.render({
                elem: '.end_time',
                type: 'date',
                max: 4073558400000,
                format: 'yyyy-MM-dd',
                // min: nowTime,
                done: function (value, date) {
                    if ($.trim(value) == '') {
                        var curDate = new Date();
                        date = {
                            'date': curDate.getDate(),
                            'month': curDate.getMonth() + 1,
                            'year': curDate.getFullYear()
                        };
                    }
                    start.config.max = date; //最小时间为开始时间的最大值  
                    start.config.max.month = date.month - 1;
                    $("input[name='end_time']").val(value);
                }
            })
        }
    });
</script>
</body>
</html>
<link rel="stylesheet" href="${ctx}/css/font/iconfontie.css" media="all"/>
<link rel="stylesheet" href="${ctx}/iconfont/iconfont.css"/>